﻿//-----------------------------------------------------------------------
// <copyright file="CrmExceptionHelper.cs" company="MSCRMTools">
//     Copyright © MSCRMTools. All rights reserved.
// </copyright>
// <author>tanguy92</author>
// <date>21/02/2011</date>
// <codeplexurl>http://searchablepropertyupdater.codeplex.com</codeplexurl>
// <summary>no summary</summary>
//-----------------------------------------------------------------------
using System;
using System.ServiceModel;

namespace CrmConnectionProject
{
    internal class CrmExceptionHelper
    {
        internal static string GetErrorMessage(Exception error, bool returnWithStackTrace)
        {
            if (error.InnerException is FaultException)
            {
                if (returnWithStackTrace)
                {
                    return ((FaultException)error.InnerException).ToString();
                }
                else
                {
                    return ((FaultException)error.InnerException).Message;
                }
            }
            else
            {
                if (returnWithStackTrace)
                {
                    return error.ToString();
                }
                else
                {
                    return error.Message;
                }
            }
        }
    }
}